/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.lib.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import javax.servlet.http.HttpSession;
import org.lucava.lib.client.service.SessionService;
import org.lucava.boatskeeper.shared.dto.UserDto;

/**
 *
 * @author glenn
 */
public class SessionServiceImpl extends RemoteServiceServlet implements SessionService {

    @Override
    public Boolean authenticate(UserDto user) {
        getSession().setAttribute("user", user);
        return true;
    }

    @Override
    public Boolean closeSession() {
        getSession().removeAttribute("user");
        return true;
    }

    @Override
    public UserDto getUser() {
        return (UserDto) getSession().getAttribute("user");
    }

    private HttpSession getSession() {
        return this.getThreadLocalRequest().getSession(true);
    }
}
